<style>
.pure_table_extra { width: 230px; border: 1px solid #aaa !important; }
.pure_table_extra a { color: #666; }
.pure_table_extra * { font-size: 12px !important; font-family: Trebuchet MS; }
</style>

<?php
$SIZE = 10;
$opts = new stdClass();
$opts->cd = 't.status = :v1';
$opts->cdv = array(':v1' => 1);
$opts->sel = 'id, name';
$pops = $orm->get('pb_ecom_product', 't.sold__', 'DESC', 1, $SIZE, $opts)->d;
$lats = $orm->get('pb_ecom_product', 't.id', 'DESC', 1, $SIZE, $opts)->d;
?>

<table class="pure-table pure_table_extra" cellPadding="0" cellSpacing="0">
  <tr><td class="ui-widget-header">最热产品</td></tr>
  <?php foreach ($pops as $idx => &$itm) { ?>
  <tr class="<?php echo ($idx % 2 == 0) ? 'pure-table-even' : 'pure-table-odd'; ?>"><td><a href="#" onclick="return Url.redirect(__redmd, __sys + '.php?i=' + __id + '&id=<?php echo $itm->id?>');"><?php echo Utils::get_short($itm->name, 20);?></a></td></tr>
  <?php } ?>
  <?php for ($i = 10 - count($pops), $il = 0; $i > $il; $i--) { ?>
  <tr class="<?php echo ($i % 2 == 0) ? 'pure-table-even' : 'pure-table-odd'; ?>"><td>&nbsp;</td></tr>
  <?php } ?>
</table>
<div>&nbsp;</div>
<table class="pure-table pure_table_extra" cellPadding="0" cellSpacing="0">
  <tr><td class="ui-widget-header">最新产品</td></tr>
  <?php foreach ($lats as $idx => &$itm) { ?>
  <tr class="<?php echo ($idx % 2 == 0) ? 'pure-table-even' : 'pure-table-odd'; ?>"><td><a href="#" onclick="return Url.redirect(__redmd, __sys + '.php?i=' + __id + '&id=<?php echo $itm->id?>');"><?php echo Utils::get_short($itm->name, 20);?></a></td></tr>
  <?php } ?>
  <?php for ($i = 10 - count($lats), $il = 0; $i > $il; $i--) { ?>
  <tr class="<?php echo ($i % 2 == 0) ? 'pure-table-even' : 'pure-table-odd'; ?>"><td>&nbsp;</td></tr>
  <?php } ?>
</table>
<div>&nbsp;</div>
<table class="pure-table pure_table_extra" cellPadding="0" cellSpacing="0">
  <thead><tr><th class="ui-widget-header">浏览过的产品</th></tr></thead>
  <tbody id="p_browsed"></tbody>
</table>

<script type="text/javascript">
  var __currs = JSON.parse('<?php echo addslashes(json_encode($currs)); ?>');
  var __default_id = '<?php echo $app_data->__default_id; ?>';
  var __requrl = '<?php echo Utils::get_requrl($app_data); ?>';
  var __redmd = '<?php echo addslashes($app_data->sys->redmd); ?>';
  var __sys = '<?php echo addslashes($app_data->sys->php_name); ?>';
  var __id = '<?php echo $app_data->param_id; ?>';
  var __login_id = '<?php echo $app_data->__login_id; ?>';
  var __curr, __browsed;
  
  $(function(){
    __browsed = Cookie.get_cookie('p_browsed');
    if (!__browsed) {
      __browsed = [];
    } else {
      __browsed = JSON.parse(__browsed);
    }
    
    render_browsed();
  });
  
  function render_browsed() {
    $('#p_browsed').empty();
    for (var idx in __browsed) {
      var itm = __browsed[idx];
      $('#p_browsed').append('<tr class="' + ((idx % 2 == 0) ? 'pure-table-even' : 'pure-table-odd') + '"><td><a href="#" onclick="return Url.redirect(__redmd, \'' + __sys + '.php?i=' + __id + '&id=' + itm.id + '\');">' + itm.name + '</a></td></tr>');
    }
    for (var i = 10 - __browsed.length, il = 0; i > il; i--) {
      var itm = __browsed[idx];
      $('#p_browsed').append('<tr class="' + ((i % 2 == 0) ? 'pure-table-even' : 'pure-table-odd') + '"><td>&nbsp;</td></tr>');
    }
    $('#p_browsed').append('<tr class="pure-table-even"><td style="text-align: right;"><a href="#" onclick="Cookie.set_cookie(\'p_browsed\', \'[]\', -1); __browsed = []; render_browsed(); return false;">清除</a></td></tr>');
  };
</script>
